home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / utility / utilwb / wbstars2.lha / WBStars2.0 / source / WBStars_CX.c < prev    next >
C/C++ Source or Header  |  1996-12-18  |  3KB  |  138 lines

  1. /* $VER: WBStars_CX.c 2.0 (18 Dec 1996)
  2. */
  3.  
  4. #include <libraries/commodities.h>
  5. #include <libraries/dos.h>
  6. #include <proto/exec.h>
  7. #include <proto/commodities.h>
  8. #include <clib/alib_protos.h>
  9.  
  10. #include "WBStars_include.h"
  11. #include "WBStars_protos.h"
  12.  
  13. #define EVT_HOTKEY    1L
  14.  
  15. struct MsgPort    *broker_mp;
  16. CxObj    *broker, *filter, *sender, *translate;
  17.  
  18. struct NewBroker    newbroker = {
  19.     NB_VERSION,
  20.     "WBStars",        
  21.     "WBStars 2.0ß by A. Pokahr (MailWare!)",
  22.     "Em: 5pokahr@informatik.uni-hamburg.de",
  23.     NBU_UNIQUE | NBU_NOTIFY,
  24.     0,    0,    0,    0
  25. };
  26.  
  27. ULONG cxsigflag;
  28.  
  29. char    InitCx()
  30. {
  31.     CxMsg *msg;
  32.     if( broker_mp=CreateMsgPort() )
  33.     {
  34.         newbroker.nb_Port = broker_mp;
  35.         cxsigflag = 1L << broker_mp->mp_SigBit;
  36.         newbroker.nb_Pri = CXpri;
  37.         if( broker=CxBroker(&newbroker,NULL) )
  38.         {
  39.             if( filter=CxFilter(hotkey) )
  40.             {
  41.                 AttachCxObj(broker, filter);
  42.                 if( sender=CxSender(broker_mp,EVT_HOTKEY) )
  43.                 {
  44.                     AttachCxObj(filter, sender);
  45.                     if( translate=(CxTranslate(NULL)) )
  46.                     {
  47.                         AttachCxObj(filter, translate);
  48.                         if( !CxObjError(filter) )
  49.                         {
  50.                             if( Activate() ) ActivateCxObj(broker, 1L);
  51.                             else ActivateCxObj(broker, 0L);
  52.                             return TRUE;
  53.                         }
  54.                     }
  55.                 }
  56.             }
  57.             DeleteCxObjAll(broker);
  58.             while( msg=(CxMsg *)GetMsg(broker_mp) )
  59.                 ReplyMsg((struct Message *)msg);
  60.         }
  61.         DeletePort(broker_mp);
  62.     }
  63.     return FALSE;
  64. }
  65.  
  66. void    RemovCx()
  67. {
  68.     CxMsg *msg;
  69.  
  70.     DeleteCxObjAll(broker);
  71.  
  72.     while( msg=(CxMsg *)GetMsg(broker_mp) )
  73.         ReplyMsg((struct Message *)msg);
  74.  
  75.     DeletePort(broker_mp);
  76. }
  77.  
  78. char    HandleCx()
  79. {
  80.     extern struct MsgPort    *broker_mp;
  81.     extern CxObj            *broker;
  82.     extern ULONG            cxsigflag;
  83.     char    dummy;
  84.     CxMsg *msg;
  85.     ULONG msgid, msgtype;
  86.  
  87.     while(msg = (CxMsg *)GetMsg(broker_mp))
  88.     {
  89.         msgid = CxMsgID(msg);
  90.         msgtype = CxMsgType(msg);
  91.         ReplyMsg((struct Message *)msg);
  92.  
  93.         switch(msgtype)
  94.         {
  95.             case CXM_IEVENT:
  96.                 switch(msgid)
  97.                 {
  98.                     case EVT_HOTKEY:
  99.                         if( activated )
  100.                         {
  101.                             Inactivate();
  102.                         }
  103.                         else
  104.                         {
  105.                             dummy=Activate();
  106.                         }
  107.                         break;
  108.                 }
  109.                 break;
  110.             case CXM_COMMAND:
  111.                 switch(msgid)
  112.                 {
  113.                     case CXCMD_DISABLE:
  114.                         ActivateCxObj(broker, 0L);
  115.                         Inactivate();
  116.                         break;
  117.                     case CXCMD_ENABLE:
  118.                         if( Activate() )    ActivateCxObj(broker, 1L);
  119.                         break;
  120.                     case CXCMD_KILL:
  121.                         return FALSE;
  122.                         break;
  123.                     case CXCMD_UNIQUE:
  124.                         return FALSE;
  125.                         break;
  126.                     case CXCMD_APPEAR:
  127.                         break;
  128.                     case CXCMD_DISAPPEAR:
  129.                         break;
  130.                 }
  131.                 break;
  132.         }
  133.     }
  134.  
  135.     if( SetSignal(0L,SIGBREAKF_CTRL_C)&SIGBREAKF_CTRL_C )return FALSE;
  136.  
  137.     return TRUE;
  138. }